// test.cpp
// Blaine Hodge
// bhodge@gpu.srv.ualberta.ca

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>

void display( void ) {

  glClearColor( 0.0, 0.0, 0.0, 0.0 );
  glEnable( GL_DEPTH_TEST );

  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();
  gluPerspective( 45.0, 1.0, 0.1, 100.0 );

  glMatrixMode( GL_MODELVIEW );
  glLoadIdentity();

  glEnable( GL_LIGHTING );

}

GLfloat LightAmbient[]    = { 0.5f, 0.0f, 0.0f, 1.0f };
GLfloat LightDiffuse[]    = { 1.0f, 0.5f, 0.5f, 1.0f };
GLfloat LightSpecular[]    = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]    = { 2.0f, 0.5f, 5.0f, 0.0f };

void idle( void ) {
  static double theta = 0.0;

  glClear( GL_COLOR_BUFFER_BIT |
    GL_DEPTH_BUFFER_BIT );

  glLightfv( GL_LIGHT0, GL_AMBIENT, LightAmbient );
  glLightfv( GL_LIGHT0, GL_DIFFUSE, LightDiffuse );
  glLightfv( GL_LIGHT0, GL_SPECULAR, LightSpecular );
  glLightfv( GL_LIGHT0, GL_POSITION, LightPosition );
  glEnable( GL_LIGHT0 );

  for ( double x = -1.0; x <= 1.0; x += 1.0 )
    for ( double y = -1.0; y <= 1.0; y += 1.0 ) {
      glPushMatrix();
      glTranslated( x, y, -4.0 );
      glRotated( theta, 1.0, 0.0, 0.0 );
      glRotated( theta, 0.0, 1.0, 0.0 );
      glRotated( theta, 0.0, 0.0, 1.0 );
      glutSolidCube( 0.5f );
      glPopMatrix();
    }

  theta += 5.0;

  glutSwapBuffers();

}

void main( int argc, char** argv ) {

  glutInit( &argc, argv );
  glutInitDisplayMode( GLUT_RGBA |
    GLUT_DOUBLE | GLUT_DEPTH );
  glutCreateWindow( "Test" );

  glutDisplayFunc( display );
  glutIdleFunc( idle );

  glutMainLoop();

}

